<div id="search">
<script>
$(document).ready(function(){
function khoainput(){
	var ma = $('input[name=ma]').val();
	var ho = $('input[name=ho]').val();
	var ten = $('input[name=ten]').val();
	var danhmuc = $('select[name=danhmuc]').val();
	if((ma=='Mã học viên') && (ho=='Họ và chữ lót') && (ten=='Tên') && (danhmuc=='')){
		$('input[name=btnSearch]').attr('disabled',true);
	} else $('input[name=btnSearch]').attr('disabled',false);
}
khoainput();
$('input[name=ma],input[name=ho],input[name=ten],select[name=danhmuc]').blur(function(){ khoainput(); });
});
</script>
<form action="administrator.php" method="get" name="kiemtra">
	<input type="hidden" name="p" value="<?php echo $p?>" />
	<input type="text" name="ma" class="txt" value="<?php if(@$_GET['ma']) echo $_GET['ma']; else echo 'Mã học viên';?>" onClick="if(value=='Mã học viên') value=''" onBlur="if(value=='') value='Mã học viên'" />
    <input type="text" name="ho" class="txt" value="<?php if(@$_GET['ho']) echo $_GET['ho']; else echo 'Họ và chữ lót';?>" onClick="if(value=='Họ và chữ lót') value=''" onBlur="if(value=='') value='Họ và chữ lót'" />
	<input type="text" name="ten" class="txt" value="<?php if(@$_GET['ten']) echo $_GET['ten']; else echo 'Tên';?>"  onClick="if(value=='Tên') value=''" onBlur="if(value=='') value='Tên'" />
    <select name="danhmuc" class="select">
    	<option value="">-- Chọn lớp --</option>
    	<?php
		$dslop = mysql_query("SELECT id,ten FROM lophoc ORDER BY ten");
		while($row_dslop = mysql_fetch_array($dslop)){
			if($_GET['danhmuc'] != $row_dslop['id']) echo "<option value=\"{$row_dslop['id']}\">{$row_dslop['ten']}</option>";
			else echo "<option value=\"{$row_dslop['id']}\" selected='selected'>{$row_dslop['ten']}</option>";
		}
		?>
    </select>
    <input type="submit" name="btnSearch" value="Tìm" class="btn" />
</form>
</div>
<?php
if(@$_GET['btnSearch']){
	$ma = trim($_GET['ma']);
	$ho = trim($_GET['ho']);
	$ten = trim($_GET['ten']);
	$danhmuc = $_GET['danhmuc'];
	$qr = "SELECT diemthi.*,concat(hocvien.id,' | ',ho,' ',hocvien.ten) as hocvien,concat(lophoc.id,' | ',lophoc.ten) as lophoc FROM diemthi,hocvien,lophoc WHERE hocvien.id=diemthi.hocvien_id AND hocvien.lophoc_id=lophoc.id ";
	if($ma != 'Mã học viên') $qr .= " AND hocvien_id='{$ma}' ";
	if($ho != 'Họ và chữ lót') $qr .= " AND ho LIKE '%{$ho}%' ";
	if($ten != 'Tên') $qr .= " AND hocvien.ten LIKE '%{$ten}%' ";
	if($danhmuc != '') $qr .= " AND diemthi.lophoc_id='{$danhmuc}' ";
	$qr .= ' ORDER BY hocvien.ten';
	$qr = mysql_query($qr);
	
	echo "
	<div class='row' style='background-color:#88C4FF; font-weight:bold'>
		<div class='col_0'>STT</div>
		<div class='col_5'>Mã lớp học</div>
		<div class='col_5'>Mã học viên</div>
		<div class='col_2' style='text-align:center'>KT L1</div>
		<div class='col_2' style='text-align:center'>KT L2</div>
		<div class='col_2' style='text-align:center'>KT L3</div>
		<div class='col_2' style='text-align:center'>KT L4</div>
		<div class='col_2' style='text-align:center'>TB ktra</div>
		<div class='col_2' style='text-align:center'>Điểm thi TN</div>
		<div class='col_2' style='text-align:center'>Điểm TN</div>
		<div class='col_2' style='text-align:center'>Xếp loại</div>
		<div style='clear:both'></div>
	</div>
	";
	$jj = 0;
	while($row_sql = mysql_fetch_array($qr)){
		$jj++;
		($row_sql['date_update']=='') ? $date_up = '' : $date_up = date('d-m-Y',strtotime($row_sql['date_update']));
		echo "<div class='row'>
		<div class='col_0'>".$jj."</div>
		<div class='col_5'>{$row_sql['lophoc']}</div>
		<div class='col_5'>{$row_sql['hocvien']}</div>
		<div class='col_2' style='text-align:center'>{$row_sql['kiemtra_lan1']}</div>
		<div class='col_2' style='text-align:center'>{$row_sql['kiemtra_lan2']}</div>
		<div class='col_2' style='text-align:center'>{$row_sql['kiemtra_lan3']}</div>
		<div class='col_2' style='text-align:center'>{$row_sql['kiemtra_lan4']}</div>
		<div class='col_2' style='text-align:center; font-weight:bold; color:blue'>{$row_sql['kiemtra_tb']}</div>
		<div class='col_2' style='text-align:center; font-weight:bold; color:blue'>{$row_sql['thi_tn']}</div>
		<div class='col_2' style='text-align:center; font-weight:bold; color:blue'>{$row_sql['diem_tn']}</div>
		<div class='col_2' style='text-align:center; color:green'>{$row_sql['xeploai']}</div>
		<div style='clear:both'></div></div>";
	}
	mysql_free_result($qr);
}
?>